package com.honey.generator.java;

import org.java.plugin.Plugin;
import org.java.plugin.PluginLifecycleException;

import com.honey.core.CorePlugin;
import com.honey.core.calculator.JavaNameCalculator;
import com.honey.core.dbmapping.structure.Structure;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.core.utils.ObjectFactory;
import com.honey.core.utils.StringUtility;

public abstract class AbstractClassName {
	
	private Plugin belongPlugin;

	private JavaNameCalculator javaNameCalculator = null ;
	
	public AbstractClassName(){
		
	}
	
	public AbstractClassName(Plugin belongPlugin ){
		this.belongPlugin = belongPlugin;
	}
	/**
	 * 创建class的类型
	 * @param schema 数据库对象
	 * @param packageName 包的名称
	 * @param postfix 类的后缀名称
	 * @param generic 泛型
	 * @param isBlob 是否包含大字段
	 * @return
	 */
	protected FullyQualifiedJavaType getClassType(Structure schema,String packageName,String postfix, String generic){
		FullyQualifiedJavaType answer = null;
		String JavaProperty = "";
		if(schema != null ) JavaProperty = schema.getJavaProperty();
		String javaProperty =getClassName(JavaProperty,postfix);
		if(StringUtility.stringHasValue(generic))
			javaProperty += generic;
		answer = new FullyQualifiedJavaType(packageName,javaProperty);
		return answer;
	}
	
	protected String getClassName(String ...str){
		return getJavaNameCalculator().classNameCalculator(str);
	}
	
	protected String getVariableName(String ...str){
		return getJavaNameCalculator().variableNameCalculator(str);
	}
	
	protected JavaNameCalculator getJavaNameCalculator(){
		if(javaNameCalculator == null){
			try {
				CorePlugin corePlugin =(CorePlugin)ObjectFactory.getRequestPlugin(belongPlugin, "honey.core.plugin");
				javaNameCalculator = corePlugin.getJavaNameCalculator();
			} catch (PluginLifecycleException e) {
				e.printStackTrace();
			}
		}
		return javaNameCalculator;
	}
}
